using UnityEngine;

//游戏关卡
public class GameLevel : PersistableObject
{
    [SerializeField]
    SpawnZone spawnZone;

    public static GameLevel Current{get;private set;}//当前关卡

    [SerializeField]
    PersistableObject[] persistableObjects;


    public Shape SpawnShape()
    {
        return spawnZone.SpawnShape();
    }

    void OnEnable()
    {
        Current = this;
        if(persistableObjects == null)
        {
            persistableObjects = new PersistableObject[0];
        }
    }

    public override void Save(GameDataWriter writer)
    {//保存每个物体
        writer.Write(persistableObjects.Length);
        for(int i = 0;i<persistableObjects.Length;i++){
            persistableObjects[i].Save(writer);
        }
    }
    public override void Load(GameDataReader reader)
    {
        int savedCount = reader.ReadInt();
        for(int i = 0;i<savedCount;i++)
        {
            persistableObjects[i].Load(reader);
        }
    }
}